<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" label-width="68px">
      <el-form-item label="收费项目" prop="sfxm">
        <el-input
          v-model="queryParams.sfxm"
          placeholder="请输入收费项目"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="收费标准" prop="sfbz">
        <el-input
          v-model="queryParams.sfbz"
          placeholder="请输入收费标准"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="业务" prop="yw">
        <el-input
          v-model="queryParams.yw"
          placeholder="请输入业务"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="类别" prop="lb">
        <el-input
          v-model="queryParams.lb"
          placeholder="请输入类别"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="部门" prop="bm">
        <el-input
          v-model="queryParams.bm"
          placeholder="请输入部门"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <span v-show="showSearch">
        <el-form-item label="类别编号" prop="xmlbbh">
        <el-input
          v-model="queryParams.xmlbbh"
          placeholder="请输入项目类别编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
        <el-form-item label="项目号" prop="xmh">
          <el-input
            v-model="queryParams.xmh"
            placeholder="请输入项目号"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="类别" prop="lb2">
          <el-input
            v-model="queryParams.lb2"
            placeholder="请输入类别"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="准确度" prop="zqd">
          <el-input
            v-model="queryParams.zqd"
            placeholder="请输入准确度"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="等级" prop="dj">
          <el-input
            v-model="queryParams.dj"
            placeholder="请输入等级"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="测量范围" prop="clfw">
          <el-input
            v-model="queryParams.clfw"
            placeholder="请输入测量范围"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="收费单位" prop="sfdw">
          <el-input
            v-model="queryParams.sfdw"
            placeholder="请输入收费单位"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="备注" prop="bz">
          <el-input
            v-model="queryParams.bz"
            placeholder="请输入备注"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
      </span>
      <el-row style="margin-bottom: 10px;">
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button type="primary" icon="el-icon-d-caret" size="mini" @click="showSearch=!showSearch">{{showSearch ? "隐藏" : "展开"}}</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
<!--        <el-button icon="el-icon-refresh" size="mini" @click="daoru">导入</el-button>-->
      </el-row>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['gd:khbjkPlus:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['gd:khbjkPlus:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['gd:khbjkPlus:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['gd:khbjkPlus:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="khbjkPlusList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
<!--      <el-table-column label="业务" align="center" prop="yw" width="55" />-->
<!--      <el-table-column label="类别" align="center" prop="lb" width="60" />-->
<!--      <el-table-column label="部门" align="center" prop="bm">-->
<!--        <template slot-scope="scope">-->
<!--          <div style="cursor: pointer;">-->
<!--            <span> {{scope.row.bm}}</span> &nbsp;-->
<!--            <el-link :underline="false" type="success" @click="copyText(scope.row.bm)" icon="el-icon-copy-document" style="font-size: 10px"></el-link>-->
<!--          </div>-->
<!--        </template>-->
<!--      </el-table-column>-->
<!--      <el-table-column label="项目类别编号" align="center" prop="xmlbbh" width="100" />-->
<!--      <el-table-column label="项目号" align="center" prop="xmh" width="60" />-->
      <el-table-column label="收费项目" align="left" prop="sfxm">
        <template slot-scope="scope">
          <div style="cursor: pointer;">
            <span> {{scope.row.sfxm}}</span> &nbsp;
            <el-link :underline="false" type="success" @click="copyText(scope.row.sfxm)" icon="el-icon-copy-document" style="font-size: 10px"></el-link>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="收费标准" align="left" prop="sfbz" width="75">
        <template slot-scope="scope">
          <div style="cursor: pointer;">
            <span> {{scope.row.sfbz}}</span> &nbsp;
            <el-link :underline="false" type="success" @click="copyText(scope.row.sfbz)" icon="el-icon-copy-document" style="font-size: 10px"></el-link>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="类别" align="left" prop="lb2"  />
      <el-table-column label="准确度" align="left" prop="zqd" />
      <el-table-column label="等级" align="left" prop="dj" />
      <el-table-column label="测量范围" align="left" prop="clfw" />
      <el-table-column label="收费单位" align="left" prop="sfdw" width="75" />
      <el-table-column label="备注" align="left" prop="bz">
        <template slot-scope="scope">
          <span style="color: #F56C6C">{{scope.row.bz}}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['gd:khbjkPlus:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['gd:khbjkPlus:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改客户报价库Plus对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="80%" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="收费项目" prop="sfxm">
              <el-input v-model="form.sfxm" placeholder="请输入收费项目" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="收费标准" prop="sfbz">
              <el-input v-model="form.sfbz" placeholder="请输入收费标准" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="收费单位" prop="sfdw">
              <el-input v-model="form.sfdw" placeholder="请输入收费单位" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="类别" prop="lb">
              <el-input v-model="form.lb" placeholder="请输入类别" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="准确度" prop="zqd">
              <el-input v-model="form.zqd" placeholder="请输入准确度" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="等级" prop="dj">
              <el-input v-model="form.dj" placeholder="请输入等级" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="测量范围" prop="clfw">
              <el-input v-model="form.clfw" placeholder="请输入测量范围" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="业务" prop="yw">
              <el-input v-model="form.yw" placeholder="请输入业务" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="部门" prop="bm">
              <el-input v-model="form.bm" placeholder="请输入部门" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="项目类别编号" prop="xmlbbh">
              <el-input v-model="form.xmlbbh" placeholder="请输入项目类别编号" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="项目号" prop="xmh">
              <el-input v-model="form.xmh" placeholder="请输入项目号" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="类别" prop="lb2">
              <el-input v-model="form.lb2" placeholder="请输入类别" />
            </el-form-item>
          </el-col>
        </el-row>


        <el-row>
          <el-col :span="24">
            <el-form-item label="备注" prop="bz">
              <el-input v-model="form.bz" :autosize="{ minRows: 3, maxRows: 4 }" type="textarea" placeholder="请输入内容" />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button :loading="buttonLoading" type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listKhbjkPlus, getKhbjkPlus, delKhbjkPlus, addKhbjkPlus, updateKhbjkPlus, importData } from "@/api/gd/khbjkPlus";

export default {
  name: "KhbjkPlus",
  data() {
    return {
      // 按钮loading
      buttonLoading: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: false,
      // 总条数
      total: 0,
      // 客户报价库Plus表格数据
      khbjkPlusList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        yw: undefined,
        lb: undefined,
        bm: undefined,
        xmlbbh: undefined,
        xmh: undefined,
        lb2: undefined,
        sfxm: undefined,
        zqd: undefined,
        dj: undefined,
        clfw: undefined,
        sfdw: undefined,
        sfbz: undefined,
        bz: undefined
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        sfxm: [
          { required: true, message: "收费项目不能为空", trigger: "blur" }
        ],
        sfbz: [
          { required: true, message: "收费标准不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    daoru() {
      importData().then(res => {

      })
    },
    copyText(data) {
      const textarea = document.createElement('textarea');
      textarea.value = data;
      document.body.appendChild(textarea);
      textarea.select();
      try {
        // 尝试执行复制操作
        const success = document.execCommand('copy');
        if (success) {
          this.$message.success("已复制！")
        } else {
          this.$message.error("复制失败！")
        }
      } catch (error) {
        this.$message.error("复制失败！")
      }
      document.body.removeChild(textarea);
    },
    /** 查询客户报价库Plus列表 */
    getList() {
      this.loading = true;
      listKhbjkPlus(this.queryParams).then(response => {
        this.khbjkPlusList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: undefined,
        yw: undefined,
        lb: undefined,
        bm: undefined,
        xmlbbh: undefined,
        xmh: undefined,
        lb2: undefined,
        sfxm: undefined,
        zqd: undefined,
        dj: undefined,
        clfw: undefined,
        sfdw: undefined,
        sfbz: undefined,
        bz: undefined
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加客户报价库Plus";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.loading = true;
      this.reset();
      const id = row.id || this.ids
      getKhbjkPlus(id).then(response => {
        this.loading = false;
        this.form = response.data;
        this.open = true;
        this.title = "修改客户报价库Plus";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          this.buttonLoading = true;
          if (this.form.id != null) {
            updateKhbjkPlus(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            }).finally(() => {
              this.buttonLoading = false;
            });
          } else {
            addKhbjkPlus(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            }).finally(() => {
              this.buttonLoading = false;
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除客户报价库Plus编号为"' + ids + '"的数据项？').then(() => {
        this.loading = true;
        return delKhbjkPlus(ids);
      }).then(() => {
        this.loading = false;
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {
      }).finally(() => {
        this.loading = false;
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('gd/khbjkPlus/export', {
        ...this.queryParams
      }, `khbjkPlus_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
